﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoGallery.Model;
using PhotoGallery.BLL;
public partial class albumAll : System.Web.UI.Page
{
    protected string myalbums="";
    protected string allalbums="";
    protected string newalbums="";
    protected void Page_Load(object sender, EventArgs e)
    {
        User u = (User)Session["user"];
        if (u == null) Response.Redirect("login.aspx");
        else
        {
            if (!IsPostBack) 
            {
                this.myalbums = showMyAlbums();
                this.allalbums = showAllAlbums();
                this.newalbums = showNewAlbums("6");//默认取出前六个
            }
        }
    }
    //显示最新相册
    private string showNewAlbums(string top)
    {
        string list = "";
        AlbumAction a = new AlbumAction();
        List<Albums> abmlist = new List<Albums>();
        string uid=((User)Session["user"]).Uid;
        //取得我的相册列表
        abmlist = a.newAlbumList(top);
        //循环取出所有相册
        foreach (Albums album in abmlist) 
        {
            PhotoAction pa = new PhotoAction();
            Picture pic = pa.showPic(album.Cover);
            list += "<li><a title="+album.Title+" href=albumshow.aspx?aid="+album.Aid+"><img src="+pic.Pic+" alt="+album.Desp+"></a></li>";
        }
        return list;
    }
    //显示所有相册
    private string showAllAlbums()
    {
        string list = "";
        AlbumAction a = new AlbumAction();
        List<Albums> abmlist = new List<Albums>();
        //取得所有相册列表
        abmlist=a.allAlbums();
        //循环取出所有相册
        foreach (Albums album in abmlist) 
        {
            PhotoAction pa = new PhotoAction();
            Picture pic = pa.showPic(album.Cover);
            list += "<li><a href=albumshow.aspx?aid=" + album.Aid + " title=" + album.Title + "><img class='groupcover' src=" + pic.Pic + " width='200px' height='120px;'></a>" +
                    "<div class='iabout'><h2><a href=albumshow.aspx?aid=" + album.Aid + ">" + album.Title + "</a></h2>" +
                        "<div class='desc'>" + album.Desp + "</div></div></li>";
        }
        return list;
    }
    //显示我的所有相册
    private string showMyAlbums()
    {
        string list = "";
        AlbumAction a = new AlbumAction();
        List<Albums> abmlist = new List<Albums>();
        string uid=((User)Session["user"]).Uid;
        //取得我的相册列表
        abmlist=a.allAlbumsofSomeone(uid);
        //循环取出所有相册
        foreach (Albums album in abmlist) 
        {
            PhotoAction pa = new PhotoAction();
            Picture pic = pa.showPic(album.Cover);
            list+="<li><a href=albumshow.aspx?aid="+album.Aid+" title="+album.Title+"><img class='groupcover' src="+pic.Pic+" width='200px' height='120px;'></a>"+
                    "<div class='iabout'><h2><a href=albumshow.aspx?aid=" + album.Aid + ">" + album.Title + "</a></h2>" +
		    			"<div class='desc'>"+album.Desp+"</div></div></li>";
        }
        return list;
    }
}